package CAS;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:34398
 * Date:2024-08-02
 * Time:8:34
 */
public class Test1 {


    private static AtomicInteger count =new AtomicInteger(0);

    public static void main(String[] args) throws InterruptedException {
        Thread thread1=new Thread(()->{
            for (int i = 0; i <5000 ; i++) {
                //count++
                count.getAndIncrement();
            }
        });
        Thread thread2=new Thread(()->{
            for (int i = 0; i <5000 ; i++) {
                //count++
                count.getAndIncrement();
            }
        });
        thread1.start();
        thread2.start();
        thread1.join();
        thread2.join();

        //获取最终加加的值  10000？
        System.out.println("count ="+count.get());
    }
}
